package com.xc.otc

import android.annotation.SuppressLint
import android.util.Log
import android.view.MotionEvent
import android.widget.FrameLayout
import android.widget.TextView
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.FragmentActivity
import com.fker.opt.JNIFKerLibs

class AdDialog : AbstractFragmentDialog<ViewDataBinding>(false, false) {
    companion object {
        fun show(activity: FragmentActivity) {
            val dialog = AdDialog()
            dialog.show(activity.supportFragmentManager, "addialog")
        }
    }

    override val layoutId: Int = R.layout.diialog_test

    var cx = 0
    var cy = 0

    @SuppressLint("ClickableViewAccessibility")
    override fun initView() {

        val adContainer = rootView?.findViewById<FrameLayout>(R.id.ad_conntainer);
        val tvBtn = rootView?.findViewById<TextView>(R.id.tvBtn);
        tvBtn?.setOnClickListener {
//            JNIFKerLibs.send(adContainer, cx, cy)
            ClickPosition.feedTemplateCasualClick(adContainer)
        }

        adContainer?.postDelayed({
            val intAr = IntArray(2)
            adContainer.getLocationInWindow(intAr)

            val x = intAr.get(0)
            val y = intAr.get(1)

            adContainer.setOnClickListener {
//                disMissDialog()
                Log.i("chyy", " ----- 我被点击了")
            }

            Log.i(
                "chyy",
                "x $x y : $y  width: ${adContainer.measuredWidth} height : ${adContainer.measuredHeight}"
            )
            cx = x + 60
            cy = y + 130

        }, 500)

        adContainer?.setOnTouchListener { _, event ->
            when (event.action) {
                MotionEvent.ACTION_DOWN -> {
                    Log.i("chyy", "down  x: ${event.x} y: ${event.y}")
                }

                MotionEvent.ACTION_UP -> {
                    Log.i("chyy", "up  x: ${event.x} y: ${event.y}")
                }

                MotionEvent.ACTION_MOVE -> {
                    Log.i("chyy", "move  x: ${event.x} y: ${event.y}")
                }


            }

            false
        }

    }


    override val isUseDataBinding: Boolean
        get() = false
}